<template>
  <div class="app-container">
    <div>
      <el-button type="primary" style="margin-bottom: 20px" @click="next1=true">下一步</el-button>
      <el-table
        :data="tableData"
        stripe
        border
        tooltip-effect="dark"
        style="margin-bottom: 30px"
        @selection-change="handleSelectionChange"
      >
        <!--选择框-->
        <el-table-column
          type="selection"
          width="55"
        />
        <el-table-column
          align="left"
          type="index"
          label="序号"
          width="60"
          style="padding-bottom: 20px"
        />
        <el-table-column
          prop="requirement"
          label="条件"
          width="180"
        />
      </el-table>
    </div>
    <div v-if="next1">
      <el-button type="warning" style="margin-bottom: 20px" @click="open">下一步</el-button>
      <el-table
        :data="multipleSelection"
        stripe
        border
        style="width: 100%"
        tooltip-effect="dark"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          align="left"
          type="index"
          label="序号"
          width="60"
          style="padding-bottom: 20px"
        />
        <el-table-column
          prop="requirement"
          label="条件"
          width="180"
        />
        <el-table-column
          prop="content"
          label="条件值"
          width="240"
        >
          <template>
            <el-input v-model="multipleSelection[0].content" placeholder="请输入" @input="forceUpdate" />
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PrizeRequirements',
  data() {
    return {
      next1: false,
      multipleSelection: [],
      tableData: [{
        requirement: '绩点'
      }, {
        requirement: '专业'
      }, {
        requirement: '排名'
      }, {
        requirement: '论文'
      }]
    }
  },
  methods: {
    forceUpdate() {
      this.$forceUpdate()
    },
    // 选择框发生改变的时候响应函数
    handleSelectionChange(val) {
      // 该数据即为选中的行的内容
      this.multipleSelection = val
      for (let i = 0; i < val.length; i++) {
        this.multipleSelection[i].content = null
      }
      console.log(this.multipleSelection)
      // console.log(val)
    },
    open() {
      this.$confirm('添加奖项条件到活动， 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '添加成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消添加'
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
